home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / lisp / modes / text-mode.el < prev    next >
Encoding:
Text File  |  1995-06-30  |  5.4 KB  |  163 lines

  1. ;;; text-mode.el --- text mode, and its idiosyncratic commands.
  2.  
  3. ;; Copyright (C) 1985, 1992, 1994 Free Software Foundation, Inc.
  4.  
  5. ;; Maintainer: FSF
  6.  
  7. ;; This file is part of XEmacs.
  8.  
  9. ;; XEmacs is free software; you can redistribute it and/or modify it
  10. ;; under the terms of the GNU General Public License as published by
  11. ;; the Free Software Foundation; either version 2, or (at your option)
  12. ;; any later version.
  13.  
  14. ;; XEmacs is distributed in the hope that it will be useful, but
  15. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  17. ;; General Public License for more details.
  18.  
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with XEmacs; see the file COPYING.  If not, write to the Free
  21. ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. ;;; Synched up with: FSF 19.28.
  24.  
  25. ;;; Commentary:
  26.  
  27. ;; This package provides the fundamental text mode documented in the
  28. ;; Emacs user's manual.
  29.  
  30. ;;; Code:
  31.  
  32. (defvar text-mode-syntax-table nil
  33.   "Syntax table used while in text mode.")
  34.  
  35. (defvar text-mode-abbrev-table nil
  36.   "Abbrev table used while in text mode.")
  37. (define-abbrev-table 'text-mode-abbrev-table ())
  38.  
  39. (if text-mode-syntax-table
  40.     ()
  41.   (setq text-mode-syntax-table (make-syntax-table))
  42.   (modify-syntax-entry ?\" ".   " text-mode-syntax-table)
  43.   (modify-syntax-entry ?\\ ".   " text-mode-syntax-table)
  44.   (modify-syntax-entry ?' "w   " text-mode-syntax-table))
  45.  
  46. (defvar text-mode-map nil
  47.   "Keymap for Text mode.
  48. Many other modes, such as Mail mode, Outline mode and Indented Text mode,
  49. inherit all the commands defined in this map.")
  50.  
  51. (if text-mode-map
  52.     ()
  53.   (setq text-mode-map (make-sparse-keymap))
  54.   (set-keymap-name text-mode-map 'text-mode-map)
  55.   (define-key text-mode-map "\t" 'tab-to-tab-stop)
  56.   (define-key text-mode-map "\es" 'center-line)
  57.   (define-key text-mode-map "\eS" 'center-paragraph))
  58.  
  59.  
  60. ;(defun non-saved-text-mode ()
  61. ;  "Like text-mode, but delete auto save file when file is saved for real."
  62. ;  (text-mode)
  63. ;  (make-local-variable 'delete-auto-save-files)
  64. ;  (setq delete-auto-save-files t))
  65.  
  66. (defun text-mode ()
  67.   "Major mode for editing text intended for humans to read.
  68. Special commands:\\{text-mode-map}
  69. Turning on Text mode calls the value of the variable `text-mode-hook',
  70. if that value is non-nil."
  71.   (interactive)
  72.   (kill-all-local-variables)
  73.   (use-local-map text-mode-map)
  74.   (setq mode-name "Text")
  75.   (setq major-mode 'text-mode)
  76.   (setq local-abbrev-table text-mode-abbrev-table)
  77.   (set-syntax-table text-mode-syntax-table)
  78.   (run-hooks 'text-mode-hook))
  79.  
  80. (defvar indented-text-mode-map ()
  81.   "Keymap for Indented Text mode.
  82. All the commands defined in Text mode are inherited unless overridden.")
  83.  
  84. (if indented-text-mode-map
  85.     ()
  86.   ;; Make different definition for TAB before the one in text-mode-map, but
  87.   ;; share the rest.
  88.   (setq indented-text-mode-map (make-sparse-keymap))
  89.   (set-keymap-name indented-text-mode-map 'indented-text-mode-map)
  90.   (set-keymap-parents indented-text-mode-map (list text-mode-map))
  91.   (define-key indented-text-mode-map "\t" 'indent-relative))
  92.  
  93. (defun indented-text-mode ()
  94.   "Major mode for editing text with indented paragraphs.
  95. In this mode, paragraphs are delimited only by blank lines.
  96. You can thus get the benefit of adaptive filling
  97.  (see the variable `adaptive-fill-mode').
  98. \\{indented-text-mode-map}
  99. Turning on `indented-text-mode' calls the value of the variable
  100. `text-mode-hook', if that value is non-nil."
  101.   (interactive)
  102.   (kill-all-local-variables)
  103.   (use-local-map text-mode-map)
  104.   (define-abbrev-table 'text-mode-abbrev-table ())
  105.   (setq local-abbrev-table text-mode-abbrev-table)
  106.   (set-syntax-table text-mode-syntax-table)
  107.   (make-local-variable 'indent-line-function)
  108.   (setq indent-line-function 'indent-relative-maybe)
  109.   (make-local-variable 'paragraph-start)
  110.   (setq paragraph-start (concat "^$\\|" page-delimiter))
  111.   (make-local-variable 'paragraph-separate)
  112.   (setq paragraph-separate paragraph-start)
  113.   (use-local-map indented-text-mode-map)
  114.   (setq mode-name "Indented Text")
  115.   (setq major-mode 'indented-text-mode)
  116.   (run-hooks 'text-mode-hook 'indented-text-mode-hook))
  117.  
  118. (defun center-paragraph ()
  119.   "Center each nonblank line in the paragraph at or after point.
  120. See `center-line' for more info."
  121.   (interactive)
  122.   (save-excursion
  123.     (forward-paragraph)
  124.     (or (bolp) (newline 1))
  125.     (let ((end (point)))
  126.       (backward-paragraph)
  127.       (center-region (point) end))))
  128.  
  129. (defun center-region (from to)
  130.   "Center each nonblank line starting in the region.
  131. See `center-line' for more info."
  132.   (interactive "r")
  133.   (if (> from to)
  134.       (let ((tem to))
  135.     (setq to from from tem)))
  136.   (save-excursion
  137.     (save-restriction
  138.       (narrow-to-region from to)
  139.       (goto-char from)
  140.       (while (not (eobp))
  141.     (or (save-excursion (skip-chars-forward " \t") (eolp))
  142.         (center-line))
  143.     (forward-line 1)))))
  144.  
  145. (defun center-line ()
  146.   "Center the line point is on, within the width specified by `fill-column'.
  147. This means adjusting the indentation so that it equals
  148. the distance between the end of the text and `fill-column'."
  149.   (interactive)
  150.   (save-excursion
  151.     (let (line-length)
  152.       (beginning-of-line)
  153.       (delete-horizontal-space)
  154.       (end-of-line)
  155.       (delete-horizontal-space)
  156.       (setq line-length (current-column))
  157.       (beginning-of-line)
  158.       (indent-to 
  159.     (+ left-margin 
  160.        (/ (- fill-column left-margin line-length) 2))))))
  161.  
  162. ;;; text-mode.el ends here
  163.